import axios from "axios";
import VueCookies from "vue-cookies";

const jzjUrl = "http://localhost:8080"

const httpPostManage = function (url = "", data = {}, contentType, rType) {
    const instance = axios.create({
        baseURL: jzjUrl,
        withCredentials: false,
        headers: {
            Accept: "application/json;charset=UTF-8",
            "Content-type": contentType ? contentType : "application/json;charset=UTF-8",
            tokenMiniAPP: VueCookies.get("tokenWeb") ? VueCookies.get("tokenWeb") : ""
        },
        responseType: rType
    });
    return instance
        .post(url, JSON.stringify(data))
        .then((result) => {
            const res = result.data;
            return Promise.resolve(res);
        })
        .catch((error) => {
            let res = error.response;
            console.log("网络请求错误");
            return res;
        });
};

export {
    jzjUrl,
    httpPostManage
};